//
// Created by 69566 on 25-8-20.
//

#ifndef DRV_KEY_H
#define DRV_KEY_H

#include "stdint.h"
#include "stdio.h"
typedef enum
{
    KEY_IDEL,
    KEY_CHECK,
    KEY_RELEASE,
    KEY_PRESS,
    KEY_SHORT_PRESS,
    KEY_LONG_PRESS,
    KEY_STATUS_MAX,
} key_status_e;

typedef enum
{
    PRESS_EVENT,
    RELEASE_EVENT,
    SHORT_PRESS_EVENT,
    LONG_PRESS_EVENT,
    EVENT_MAX,
} key_event_e;

typedef void (*key_event_callback)(void);
typedef uint8_t (*gpio_read_fn)(void);

typedef struct
{
    uint8_t            current_leavel; // 当前电平
    uint8_t            valid_leavel;   // 有效电平
    gpio_read_fn       gpio_read;
    key_status_e       status;
    uint32_t           current_time;
    uint32_t           last_time;
    key_event_callback event_callback[EVENT_MAX];
} key_info_t;

key_info_t *key_init( gpio_read_fn callback, uint8_t valid_leavel);

void   key_event_register(key_info_t* key, key_event_e event, key_event_callback callback);
void   drv_key_handle();
#endif // DRV_KEY_H
